//
//  DateEntity.swift
//  SimpleCal
//
//  Created by 杜晓祥 on 2021/10/20.
//

import Foundation

struct DateEntity :CustomStringConvertible{
    var lunar:LunarEntity
    var solar:SolarEntity
    var dayType:DayType = .general
    var currentMonth:Bool = true
    
    init(lunar: LunarEntity, solar: SolarEntity) {
        self.lunar = lunar
        self.solar = solar
        dayType = .general
        if solar.isWeek() {
            dayType = .week
        }
    }
    init(lunar: LunarEntity, solar: SolarEntity, dayType: DayType, currentMonth:Bool) {
        self.lunar = lunar
        self.solar = solar
        self.dayType = dayType
        self.currentMonth = currentMonth
    }
    var description: String {
        return "\(lunar), \(solar)"
    }
    
    enum DayType: Int {
        /**
         正常日期，为当月、非当月日期信息，不包含节假日、节日、周末等日期
         */
        case general = 0
        /**
         节假日，通常为国家法定节假日，展示为放假日
         */
        case holiday = 1
        /**
         节假日，倒休日，展示为周末加班日
         */
        case work = 2
        /**
         周六、周日
         */
        case week = 3
        
        /**
         当天
         */
        case currentDay = 4
        
        case festvial = 5

    }
}
extension DateEntity {
    
    func statusString () -> String {
        let s1 = self.solar.dateFormatter(formatter: "yyyy年MM月dd日")
        let s2 = self.lunar
        let ss2 = s2.monthStr + s2.dayStr
        return s1 + " " + ss2
    }
    
    func equal (date: DateEntity) -> Bool {
        let s1 = date.solar
        let s2 = self.solar
        if s1.year == s2.year && s1.month == s2.month && s1.day == s2.day {
            return true
        }
        return false
    }
    
    func equalMonth (date: DateEntity) -> Bool {
        let s1 = date.solar
        let s2 = self.solar
        if s1.year == s2.year && s1.month == s2.month {
            return true
        }
        return false
    }
    /**
     传入的日期对象，是否为当前日期的上一月
     */
    func preMonth (date: DateEntity) -> Bool {
        let s1 = date.solar
        let s2 = self.solar
        if s1.year == s2.year && s1.month - 1 == s2.month {
            return true
        }
        return false
    }
    /**
     传入的日期对象，是否为当前日期的下一月
     */
    func nextMonth (date: DateEntity) -> Bool {
        let s1 = date.solar
        let s2 = self.solar
        if s1.year == s2.year && s1.month == s2.month {
            return true
        }
        return false
    }
    
    func getFormatterDefault () ->String {
        let d1 = self.solar.dateFormatter(formatter: "yyyy年MM月dd日")
        let d2 = self.lunar.lunarMonthDay
        let d4 = self.solar.getSimpleWeek()
        let d3 = self.solar.dateFormatter(formatter: "HH:mm:ss")
        return d1 + " " + d2 + " " + d4 + " " + d3
    }
}
